<template>
    <div class="container">
        <view :style="{ height: titleBarMarginTop }"></view>
        <view class="styleTitleContainer">
            <view class="styleTitleLeft">
                <image class="styleGoBack" :src="srcGoBack" @click="clickBack" v-if="pagesLength >= 2"></image>
                <image class="styleGoBack" :src="srcGoHome" @click="clickHome" v-else></image>
            </view>
            <view class="styleTitleCenter">
                <span class="styleTitleContent">AI面评</span>
            </view>
            <view class="styleTitleRight"></view>
        </view>
        <div class="div-btn-container">
            <div class="btn-open-ai-interview" @click="goToAiInterview" ref="divOpenAIInterview">打开AI面评</div>
        </div>
    </div>
</template>
<script>
import { refAddPoint } from "@/api/modules/company.js";
export default {
    data() {
        return {
            srcGoBack: this.$imgBaseSelf + "career/positionDictionary/major_go_back.webp",
            srcGoHome: this.$imgBaseSelf + "home-b.png",
            fromtag: '',
            pagesLength: 0,
            statusBarHeight: 0,
            titleBarMarginTop: 0
        }
    },
    onLoad(opt) {
        if (opt) {
            this.fromtag = opt.fromtag;
        }
    },
    created() {
        this.pagesLength = getCurrentPages().length;
        console.log("pagesLength:" + this.pagesLength);
    },
    mounted() {
        console.log("mounted");
        this.commitBuringPoint("enterAIInterviewActivity");
        this.getStatusBarHeight();
    },
    methods: {
        goToAiInterview() {
            let personId = uni.getStorageSync("person-id").slice(2) || '';
            uni.navigateTo({
                url:
                    "/pagesSub/companyCenter/interviewAI/majorSearchAI?from=zhadui&channel=activity&personId=" + personId + "&fromtag=" + this.fromtag,
            });
            this.commitBuringPoint("clickAIInterviewActivity");
        },
        commitBuringPoint(optCode) {
            let personId = uni.getStorageSync("person-id").slice(2) || '';
            var modelType = "";
            if (this.from == 'zhadui') {
                modelType = "demonstrate";
            }
            const params = {
                optCode: optCode,
                platform: "1",
                personId: this.personId,
                moduleType: modelType,
                remark: "fromtag=" + this.fromtag
            };

            refAddPoint(params).then(res => {
                if (res.code == 200) {
                    console.log("commitBuringPoint", res);
                }
            })
        },
        getStatusBarHeight() {
            const res = uni.getSystemInfoSync();
            this.statusBarHeight = res.statusBarHeight;
            this.titleBarMarginTop = this.statusBarHeight + "px";
        },
        clickBack() {
            console.log("clickBack");
            uni.navigateBack();
        },
        clickHome() {
            uni.switchTab({
                url: "/pages/index/index",
            });
        },
    }
}
</script>
<style lang="scss" 
scoped>
.container {
    width: 100vw;
    height: 100vh;
    background-image: url("https://img3.job1001.com/ypMp/elan/images/career/h5_go_to_ai_interview_bg.png");
    background-size: cover;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;

    .styleTitleContainer {
        height: 88rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .styleTitleLeft {
            flex: 1;

            .styleGoBack {
                width: 44rpx;
                height: 44rpx;
                margin-left: 32rpx;
            }
        }

        .styleTitleCenter {
            flex: 1;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;

            .styleTitleContent {
                font-weight: 800;
                color: #222222;
                line-height: 44rpx;
                font-size: 32rpx;
            }
        }

        .styleTitleRight {
            flex: 1;
        }
    }
}

.div-btn-container {
    position: fixed;
    bottom: 37px;
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: center;
}

.btn-open-ai-interview {
    height: 100%;
    width: 100%;
    background-color: #f7663e;
    margin-left: 20px;
    margin-right: 20px;
    color: white;
    display: flex;
    border-radius: 8px;
    justify-content: center;
    align-items: center;
}
</style>